This invention relates to the field of garbage collection within a computing device. More particularly, apparatus and methods are provided for adaptively triggering garbage collection based on observed rates of memory allocation and/or allocations of memory during garbage collection.
There are trade-offs in any garbage collection scheme. Triggering garbage collection to recycle or free used memory too often will decrease an application's throughput, because less CPU time will be used to execute the application. Triggering it infrequently, however, may cause relatively high post times (periods of time during which the application is posted or paused while the garbage collector performs critical work) and, if invoked too infrequently could even cause the application to run out of memory.
Traditional garbage collection schemes tend to employ fixed free memory thresholds, such that the garbage collection process is initiated whenever the amount of free memory drops below a fixed threshold. One problem with using a fixed free memory threshold as a trigger for initiating garbage collection is that memory may be consumed at different rates at different times. If the fixed free memory threshold is set too high during periods of slow consumption, garbage collection may be invoked too often. If set too low during a period of relatively high consumption, the application's memory may be exhausted before garbage collection is performed.
By applying fixed thresholds, traditional garbage collectors try to avoid operating too often, and therefore generally promote application throughput over low post times. However, a real-time application may not be able to tolerate any post time or anything more than a minimal post time.
Therefore, a garbage collector that operates in conjunction with a real-time application may be required to recycle the application's memory without denying processor resources to real-time threads, and to do so frequently enough and fast enough to prevent the exhaustion of free memory and blocking of the real-time threads. Although a real-time garbage collector should be granted sufficient processor cycles to execute swiftly, allocating too many cycles should be avoided so as to avoid reducing the application's throughput unnecessarily.
Adding further complexity, however, real-time garbage collection may need to be performed concurrently—that is, in parallel with one or more application threads. This is particularly important in multi-core computing systems. Without concurrency, all application threads may have to halt during garbage collection of their memory.